<?php
/**
 * Created by PhpStorm.
 * User: iceberg
 * Date: 2018-10-20
 * Time: 1:04
 */

namespace app\work\controller;


use app\service\OutorderService;
use think\Controller;

class Outorder extends Controller
{
    //出库业务
    private $outorderService;
    //初始化
    public function initialize()
    {
        $this->outorderService = new OutorderService();
    }

    //分页列表
    public function index()
    {
        $this->assign('list', $this->outorderService->page());
        $this->assign('count', $this->outorderService->count());
        return $this->fetch();
    }

    //显示创建页面
    public function create()
    {
        $category = $this->outorderService->getCategory();
        $lst_category = get_tree($category);
        $this->assign('category', $lst_category);
        $this->assign('supplier', $this->outorderService->getSupplier());
        $this->assign('unit', $this->outorderService->getUnit());
        $this->assign('storage', $this->outorderService->getStorage());
        return $this->fetch();
    }

    //保存出库单
    public function save()
    {
        return $this->outorderService->save();
    }

    //显示编辑界面
    public function edit($id)
    {
        //dump($this->inorderService->getGoodsByOrderID($id));die;
        $category = $this->outorderService->getCategory();
        $lst_category = get_tree($category);
        $this->assign('supplier', $this->outorderService->getSupplier());
        $this->assign('category', $lst_category);
        $this->assign('unit', $this->outorderService->getUnit());
        $this->assign('storage', $this->outorderService->getStorage());
        $this->assign('info', $this->outorderService->getOrder($id));
        $this->assign('glist', $this->outorderService->getGoodsByOrderID($id));
        return $this->fetch();
    }

    //更新订单
    public function update()
    {
        return $this->outorderService->update();
    }

    //删除
    public function delete($id)
    {
        return $this->outorderService->delete($id);
    }

    //打印
    public function prints($id)
    {
        $this->assign('info', $this->outorderService->getOrder($id));
        $this->assign('glist', $this->outorderService->getGoodsByOrderID($id));
        return $this->fetch();
    }
}